// components/nav/index.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  options: {
    addGlobalClass: true
  },
  properties: {
    title: {
      type: String,
      value: '标题'
    },
    isShowBack: {
      type: String,
      value: "false"
    },
    isShowLocation: {
      type: Boolean,
      value: false
    },
    locationName:{
      type:String,
      value:"深圳"
    },
    isShowHome:{
      type:Boolean,
      default:false
    }
  },
  externalClasses: ['custom-class'],
  /**
   * 组件的初始数据
   */
  data: {
    deviceInfo: {
      statusBarHeight: app.globalData.statusBarHeight,
      titleBarHeight: app.globalData.titleBarHeight
    },
    pages:1
  },
  lifetimes: {
    attached: function () {
      let pages = getCurrentPages();
      let len = pages.length;
      this.setData({
        pages:len
      });
      if(len > 1){
        this.setData({
          isShowBack:true
        });
      }
      //如果层级大于4或者分享场景进来,增加返回首页
      console.log('show current page delta ' + len);
      if (len > 4 || (len == 1 && !app.checkIsTab(`/${pages[0].route}`) &&app.globalData.shareScene)) {
        this.setData({
          isShowHome: true
        });
      }
      console.log(pages);
    },
    moved: function () { },
    detached: function () { },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    goback: function () {
      wx.navigateBack({
        delta: 1,
      })
    },
    goHome(){
      wx.switchTab({
        url: '/pages/index/index',
      })
      // wx.navigateBack({
      //   delta: this.data.pages,
      // })
    }
  }
})
